<template>
    <!-- pages/announcementdetails/index.wxml -->
    <view class="detailsbox" :style="'padding-bottom:' + marginBottom + 'rpx;'">
        <view class="title">
            {{ detail.title }}
        </view>
        <image v-if="detail.path" :src="detail.path"></image>
        <rich-text class="content" :nodes="detail.content">
            <!-- {{detail.desc}} -->
        </rich-text>
        <view class="flexbox">
            <view class="author">发布者：{{ detail.author }}</view>
            <view class="author">{{ detail.createtime }}</view>
        </view>
    </view>
</template>

<script>
// pages/announcementdetails/index.js
const app = getApp(); // 引入app

const _request = require('../../utils/request.js'); // 引入require;

export default {
    data() {
        return {
            marginBottom: app.globalData.marginBottom,
            imgUrl: app.globalData.imgUrl,
            //全局img路径
            detail: {
                title: '',
                path: '',
                content: '',
                author: '',
                createtime: ''
            },
            path: ''
        };
    }
    /**
     * 生命周期函数--监听页面加载
     */,
    onLoad: function (options) {
        // 获取详情
        _request
            .get(
                '/bulletin/findBulletin',
                {
                    userId: uni.getStorageSync('userid'),
                    id: options.id
                },
                app.globalData.msgType
            )
            .then((res) => {
                res.data.data.createtime = this.timestampToTime(res.data.data.createtime, 6);
                res.data.data.desc = res.data.data.desc.replace(/↵/g, '/n');
                this.setData({
                    detail: res.data.data
                });
            })
            .catch((error) => {});
    },
    methods: {
        timestampToTime: function (timestamp) {
            var date = new Date(timestamp);
            var YY = date.getFullYear() + '-';
            var MM = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
            var DD = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
            return YY + MM + DD;
        }
    }
};
</script>
<style>
/* pages/announcementdetails/index.wxss */
page {
    background: #fbfbfb;
    position: relative;
}

.detailsbox {
    margin: 20rpx 40rpx 0 40rpx;
    width: 670rpx;
}

/* 图片 */
.detailsbox > image {
    width: 670rpx;
    height: 300rpx;
}

/* title */
.title {
    width: 670rpx;
    /* height: 88rpx; */
    font-size: 32rpx;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: 500;
    color: #333333;
    line-height: 44rpx;
    margin: 30rpx 0 40rpx 0;
    text-align: center;
}

/* content */
.content {
    width: 670rpx;
    font-size: 28rpx;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #666666;
    line-height: 40rpx;
    margin-bottom: 70rpx;
}

/* 作者和时间 */
.flexbox {
    width: 670rpx;
    display: flex;
    flex-wrap: nowrap;
    justify-content: space-between;
    font-size: 24rpx;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #999999;
    padding: 24rpx 0;
}
</style>
